package com.mes.cloud.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mes.cloud.dao.BmeBcAppletDAO;
import com.mes.cloud.dto.BmeBcAppletDTO;
import com.mes.cloud.service.BmeBcAppletService;
import com.mes.cloud.util.CommPager;
import com.mes.cloud.util.UuId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 视图项配置
 *
 * @author wxm
 * @Time 2019-6-26
 */
@Service
public class BmeBcAppletServiceImpl implements BmeBcAppletService {
    private static final String FUN = "fun";

    @Autowired
    private BmeBcAppletDAO bmeBcAppletDAO;

    @Override
    public List<BmeBcAppletDTO> getList(Map<Object, Object> condition) {
        return bmeBcAppletDAO.getList(condition);
    }

    @Override
    public long getCount(Map<Object, Object> condition) {
        return bmeBcAppletDAO.getCount(condition);
    }

    @Override
    public long insert(BmeBcAppletDTO bmeBcAppletDTO) {
        bmeBcAppletDTO.setId(UuId.getShortUuid());
        return bmeBcAppletDAO.insert(bmeBcAppletDTO);
    }

    @Override
    public long update(BmeBcAppletDTO bmeBcAppletDTO) {
        List<BmeBcAppletDTO> list = new ArrayList<BmeBcAppletDTO>();
        //删除配置信息
        bmeBcAppletDAO.delByCodeAppletViewId(bmeBcAppletDTO);
        //插入配置信息
        return insert(bmeBcAppletDTO);
    }

    @Override
    public long delete(Integer id) {
        return bmeBcAppletDAO.delete(id);
    }

    @Override
    public BmeBcAppletDTO get(Integer id) {
        return bmeBcAppletDAO.get(id);
    }

    @Override
    public CommPager<BmeBcAppletDTO> getPageList(Map<Object, Object> map) {
        int pageIndex = map.get("pageIndex") == null ? 0 : Integer.valueOf(map.get("pageIndex").toString());
        int pageSize = map.get("pageSize") == null ? 10 : Integer.valueOf(map.get("pageSize").toString());
        Page<BmeBcAppletDTO> page = PageHelper.startPage(pageIndex, pageSize, true);
        List<BmeBcAppletDTO> list = bmeBcAppletDAO.getList(map);
        CommPager<BmeBcAppletDTO> pageResult = new CommPager<>(page, list);
        return pageResult;
    }
}
